package com.itheima.common.exception;

import com.itheima.common.Code;
import com.itheima.common.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Component
public class MyExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    public Result BizException(BusinessException ex) {
        return ex.getResult();
    }

    @ExceptionHandler(Exception.class)
    public Result BizException(Exception ex) {
        System.out.println(ex);
        return new Result(Code.ERROR, "您的网络有问题，请稍后重试！");
    }

}
